package com.chen.servlet;/*
package com.chen.servlet;

import com.chen.entity.FlightEntity;
import com.chen.service.FlightService;
import com.chen.utils.DateUtils;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.Date;

@WebServlet("/insertFlight")
public class InsertFlightServlet extends HttpServlet {
    private FlightService flightService = new FlightService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getRequestDispatcher("insertFlight.jsp").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            String phone = req.getParameter("phone");
            flightService.strIsEmpty(phone, req, resp);

            String flightId = req.getParameter("flightId");
            flightService.strIsEmpty(flightId, req, resp);

            String company = req.getParameter("company");
            flightService.strIsEmpty(company, req, resp);

            String departureAirport = req.getParameter("departureAirport");
            flightService.strIsEmpty(departureAirport, req, resp);

            String arriveAirport = req.getParameter("arriveAirport");
            flightService.strIsEmpty(arriveAirport, req, resp);

            // 将日期string类型转化成date
            String departureTimeStr = req.getParameter("departureTime");
            flightService.strIsEmpty(departureTimeStr, req, resp);
            Date departureTime = DateUtils.stringToDate(departureTimeStr);

            String arriveTimeStr = req.getParameter("arriveTime");
            flightService.strIsEmpty(arriveTimeStr, req, resp);
            Date arriveTime = DateUtils.stringToDate(arriveTimeStr);

            String model = req.getParameter("model");
            flightService.strIsEmpty(model, req, resp);

            String costStr = req.getParameter("cost");
            flightService.strIsEmpty(costStr, req, resp);
            Float cost = Float.parseFloat(costStr);

            //将数据置入实体中
            FlightEntity flightEntity = flightService.setEntity(null, flightId,
                    company, departureAirport, arriveAirport, departureTime,
                    arriveTime, model, cost);

            int result = flightService.insertFlight(flightEntity);
            if (result <= 0) {
                // 修改失败的情况下
                req.setAttribute("errorMsg", "插入失败!");
                req.getRequestDispatcher("error.jsp").forward(req, resp);
                return;
            }
            // 如果插入成功的情况下  则重定向到showFlight 查询航班信息
            req.setAttribute("phone", phone);
            req.getRequestDispatcher("showFlight").forward(req, resp);
        } catch (Exception e) {
            e.printStackTrace();
            // 修改失败的情况下
            req.setAttribute("errorMsg", "系统错误!");
            req.getRequestDispatcher("error.jsp").forward(req, resp);
        }
    }
}*/
